import { ErrorRes } from "../res-model";
import { findEventsService } from "../service/event-data";

export const getEventData = async (
  data: any = {},
  startDate: string,
  endDate: string,
) => {
  const { label } = data;
  if (label == null) {
    return new ErrorRes({ code: 99999, message: "参数缺失" });
  }

  const start = startDate ? new Date(`${startDate} 0:00:00`) : null;
  const end = endDate ? new Date(`${endDate} 23:59:59`) : null;

  // 获取数据
  const result = await findEventsService(
    {
      eventKey: label,
    },
    start,
    end,
  );

  return result;
};
